const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");

const routes = require("./routes"); //导入自定义路由文件，创建模块化路由
const response = require("./utils/response"); //导入请求响应封装
global.response = response;//注册到全局

const app = express();

//日志管理 引入log4js配置，初始化全局对象
const log4js = require("./utils/logUtil");
const logger = log4js.getLogger("default"); // 使用默认类别
global.logger = logger; // 赋值给全局对象【logger】，也可以直接替换【console】
// global.console = logger
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", routes);

module.exports = app;
